package com.luseen.luseenbottomnavigation.BottomNavigation;

import ohos.agp.animation.AnimatorValue;
import ohos.agp.colors.RgbColor;
import ohos.agp.components.Component;
import ohos.agp.components.Image;
import ohos.agp.components.Text;
import ohos.agp.components.element.ShapeElement;
import ohos.app.Context;
import ohos.global.resource.solidxml.TypedAttribute;

class BottomNavigationUtils {

    static void changeImageColorFilter(final Image image, int fromColor, RgbColor toColor) {
        AnimatorValue imageColorChangeAnimation = new AnimatorValue();
        imageColorChangeAnimation.setValueUpdateListener(new AnimatorValue.ValueUpdateListener() {
            @Override
            public void onUpdate(AnimatorValue animatorValue, float v) {
                ShapeElement element = new ShapeElement();
                element.setRgbColor(new RgbColor(toColor));
                image.setBackground(element);
            }
        });
        imageColorChangeAnimation.setDuration(150);
        imageColorChangeAnimation.start();
    }

    static void changeViewBackgroundColor(final Component view,
                                          RgbColor fromColor, RgbColor toColor) {
        AnimatorValue imageColorChangeAnimation = new AnimatorValue();
        imageColorChangeAnimation.setValueUpdateListener(new AnimatorValue.ValueUpdateListener() {
            @Override
            public void onUpdate(AnimatorValue animatorValue, float v) {
                ShapeElement element = new ShapeElement();
                element.setRgbColor(toColor);
                view.setBackground(element);
            }

        });
        imageColorChangeAnimation.setDuration(150);
        imageColorChangeAnimation.start();
    }

    static void changeViewTopPadding(final Component view, int fromPadding, int toPadding) {
        AnimatorValue animator = new AnimatorValue();
        animator.setDuration(150);
        animator.setValueUpdateListener(new AnimatorValue.ValueUpdateListener() {
            @Override
            public void onUpdate(AnimatorValue animatorValue, float v) {
                view.setPadding(view.getPaddingLeft(),
                        toPadding,
                        view.getPaddingRight(),
                        view.getPaddingBottom());
            }
        });

        animator.start();
    }

    static void changeRightPadding(final Component view, int fromPadding, int toPadding) {
        AnimatorValue animator = new AnimatorValue();
        animator.setDuration(150);
        animator.setValueUpdateListener(new AnimatorValue.ValueUpdateListener() {
            @Override
            public void onUpdate(AnimatorValue animatorValue, float v) {
                view.setPadding(view.getPaddingLeft(),
                        view.getPaddingTop(),
                        toPadding,
                        view.getPaddingBottom());
            }

        });
        animator.start();
    }

    static void changeViewLeftPadding(final Component view, int fromMargin, int toMargin) {
        AnimatorValue animator = new AnimatorValue();
        animator.setDuration(3000);
        animator.setValueUpdateListener(new AnimatorValue.ValueUpdateListener() {
            @Override
            public void onUpdate(AnimatorValue animatorValue, float v) {
                view.setPadding(
                        toMargin,
                        view.getPaddingTop(),
                        view.getPaddingRight(),
                        view.getPaddingBottom());
                view.postLayout();
            }
        });
        animator.start();
    }

    static void changeTextSize(final Text textView, float from, float to) {
        AnimatorValue textSizeChangeAnimator = new AnimatorValue();
        textSizeChangeAnimator.setDuration(150);
        textSizeChangeAnimator.setValueUpdateListener(new AnimatorValue.ValueUpdateListener() {
            @Override
            public void onUpdate(AnimatorValue animatorValue, float v) {
                textView.setTextSize((int) to, Text.TextSizeType.FP);
            }
        });
        textSizeChangeAnimator.start();
    }


    static int getActionbarSize(Context context) {
        int actionbarSize = -1;
        TypedAttribute typedValue = null;
        actionbarSize = 168;
        return actionbarSize;

    }

}
